package com.diy.common.dao.page;


import java.sql.Connection;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Signature;
import org.apache.ibatis.session.RowBounds;

/**
 * Created by GY on 2015/11/30.
 */

@Intercepts(
        @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class})
)
public class MySQLPagingInterceptor extends AbstractPagingInterceptor {

    @Override
    public String getNewSql(String oldSql, RowBounds rowBounds) {
        int offset = rowBounds.getOffset();
        int limit = rowBounds.getLimit();
        return oldSql + String.format(" LIMIT %d, %d", offset, limit);
    }
}